import 'package:flutter/material.dart';

class CategorySidebar extends StatefulWidget {
  const CategorySidebar({Key? key}) : super(key: key);

  @override
  State<CategorySidebar> createState() => _CategorySidebarState();
}

class _CategorySidebarState extends State<CategorySidebar> {
  int _selectedIndex = 0;

  final List<String> _categories = [
    '推荐',
    '经典',
    '教材',
    '医案',
    '方剂',
    '本草',
    '针灸',
    '诊断',
    '其他',
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 100,
      color: Colors.grey[100],
      child: ListView.builder(
        itemCount: _categories.length,
        itemBuilder: (context, index) {
          return InkWell(
            onTap: () {
              setState(() {
                _selectedIndex = index;
              });
            },
            child: Container(
              padding: const EdgeInsets.symmetric(vertical: 16),
              decoration: BoxDecoration(
                color: _selectedIndex == index
                    ? const Color(0xFFBFA47C).withOpacity(0.2)
                    : null,
                border: Border(
                  left: BorderSide(
                    color: _selectedIndex == index
                        ? const Color(0xFFBFA47C)
                        : Colors.transparent,
                    width: 4,
                  ),
                ),
              ),
              child: Text(
                _categories[index],
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: _selectedIndex == index
                      ? const Color(0xFFBFA47C)
                      : Colors.black87,
                  fontWeight: _selectedIndex == index
                      ? FontWeight.bold
                      : FontWeight.normal,
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}
